package com.huidu.bitrade.result.page;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huidu.bitrade.constant.PageModel;
import com.huidu.bitrade.result.PageResultByJPA;

public class PageCondition {

    public static IPage page(MpPageQuery mpPageQuery){
        Page<Object> objectPage = new Page<>();
        objectPage.setCurrent(mpPageQuery.getPageNo());
        objectPage.setSize(mpPageQuery.getPageSize());
        return objectPage;
    }
    public static IPage page(AwardExportQuery awardExportQuery){
        Page<Object> objectPage = new Page<>();
        objectPage.setCurrent(awardExportQuery.getPageNo());
        objectPage.setSize(awardExportQuery.getPageSize());
        return objectPage;
    }

    public static IPage page(PageModel pageModel){
        Page<Object> objectPage = new Page<>();
        objectPage.setCurrent(pageModel.getPageNo());
        objectPage.setSize(pageModel.getPageSize());
        return objectPage;
    }

    public static PageResultByJPA buildData(Page page){
        return PageResultByJPA.builder()
                .totalPages((int) page.getPages())
                .totalElements(page.getTotal())
                .content(page.getRecords())
                .isLast(!page.hasNext())
                .size((int) page.getSize())
                .build();
    }
}
